package com.wk.ums.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wk.common.bean.Resp;
import com.wk.ums.entity.Member;
import com.wk.ums.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/member")
public class MemberController {

    @Autowired
    private MemberService  memberService;


    /**
     * 用户登录
     */
    @GetMapping("query")
    public Resp<Member> queryUser(@RequestParam("username") String username, @RequestParam("password") String password) {
        Member member = memberService.queryUser(username,password);
        return Resp.ok(member);
    }

    /**
     * 用户注册
     * @param member    用户对象
     * @param code      验证码
     */
    @PostMapping("register")
    public Resp<Void> register(Member member,@RequestParam("code") String code){
        memberService.register(member,code);
        return Resp.ok(null);
    }

    /**
     * 检查注册用户的信息是否可用
     * @param type  1       2     3
     * @param data 用户名  手机号  邮箱
     * @return true：可用；false：不可用
     */
    @GetMapping("check/{data}/{type}")
    public Resp<Boolean> checkData(@PathVariable(value = "data") String data,@PathVariable(value = "type") Integer type){
        Boolean flag = memberService.checkData(data,type);
        return Resp.ok(flag);
    }

    /**
     * 根据用户ID查询用户信息
     */
    @GetMapping("{id}")
    Resp<Member> info(@PathVariable("id") Long id) {
        return Resp.ok(memberService.getById(id));
    }
}

